package com.lantosec.hmrp.core.util;

import org.springframework.util.StringUtils;

public class GeneratorUtils {

	/**
	 * 通过类的全路径取所在的包的全路径
	 * 
	 * @param path
	 * @return
	 */
	public static String getPackageFromPath(String path) {
		return path.substring(0, path.lastIndexOf("."));
	}

	/**
	 * 通过类的全路径取类名
	 * 
	 * @param path
	 * @return
	 */
	public static String getClassNameFromPath(String path) {
		return path.substring(path.lastIndexOf(".") + 1);
	}

	/**
	 * 通过类的全路径名，取用户的生成路径
	 * 
	 * @param path
	 * @return
	 */
	public static String getPathFromClassPath(String path) {
		return StringUtils.replace(path, ".", "/");
	}

	public static String getRootPath(){
		String path = Thread.currentThread().getContextClassLoader().getResource("").toString();
		path = StringUtils.replace(path,"file:/","");
		path = StringUtils.replace(path,"/target/classes/","/src/main/java/");
		path = StringUtils.replace(path,"/target/test-classes/","/src/main/java/");
		return path;
	}

	public static String getPackagePath(String packageName){
		return getRootPath() + StringUtils.replace(packageName, ".", "/") + "/";
	}

	public static String getJavaFile(String className){
		return className + ".java";
	}
}
